package cn.wolfcode.web.controller;

import cn.wolfcode.domain.MessageReply;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IMessageReplyService;
import cn.wolfcode.util.RequiredPermission;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/index1")
public class MessageReplyController {
    @Autowired
    private IMessageReplyService  messageReplyService;
    @RequestMapping("/listReply")
    @RequiredPermission(name="留言详情查询",expression = "messageReply:list")
    public String list(Model model,QueryObject qo){
        PageInfo<MessageReply> pageInfo = messageReplyService.query(qo);
        model.addAttribute("pageInfo",pageInfo);
        return "reply";


//                List<MessageReply> messageReplys = messageReplyService.listAll();
//        model.addAttribute("messageReplys",messageReplys);
//        return "messageReply/list";  //找视图 / WEB-INF/views/messageReply/list.jsp
    }
    @RequestMapping("/delete")
    @RequiredPermission(name="留言详情删除",expression = "messageReply:delete")
    public String delete(Long id){
        if (id!=null) {
            messageReplyService.delete(id);
        }
        return "redirect:/messageReply/list";  //让浏览器重新发一次请求
    }
    @RequestMapping("/input")
    @RequiredPermission(name="留言详情新增或修改",expression = "messageReply:input")
    public String input(Long id,Model model){
        if (id!=null) {
            MessageReply messageReply = messageReplyService.get(id);
            model.addAttribute("messageReply",messageReply);
        }
        return "messageReply/input";
    }

    @RequestMapping("/saveOrUpdate")
    @RequiredPermission(name="留言详情新增或修改",expression = "messageReply:saveOrUpdate")
    public String saveOrUpdate(MessageReply messageReply){
        if (messageReply.getId()!=null) {
            messageReplyService.update(messageReply);
        }else {
          messageReplyService.save(messageReply);
        }
        return "redirect:/messageReply/list";
    }
}
